#include <iostream>
#include <typeinfo>

using std::cout;
using std::endl;

class C{};
class B{
#ifdef POLYMORPH 
    virtual void f()=0;
#endif //POLYMORPH
};

class D : public B{
    void f() {}
};

typedef enum {
    E1,
    E2,
}ET;

int main() {
    int n;
    //n = static_cast<int>(E1); //可隐式转换
    n = E1;
    float f = E2;
    ET e = static_cast<ET>(n);
    //ET e = n; //error, 只能显式强制转换

    const char *pc; char *cp = const_cast<char*>(pc);
    const char &cr = *pc; 
    //char &cr = cr; //error
    char &cr1 = const_cast<char&>(cr); 
    char &cr2 = const_cast<char&>(*pc);

    //n = pc; //error
    //n = static_cast<int>(pc); //error
    n = reinterpret_cast<long long>(pc);     

    C oc1;
    D *dp0 = reinterpret_cast<D*>(&oc1); //无相关类转换
    char *cp2 =reinterpret_cast<char*>(n);


    B *bp = new D;
    D *dp = static_cast<D*>(bp);
    dp = dynamic_cast<D*>(bp);
    B &br = *bp;
    D &dr = static_cast<D&>(br);
    D &dr2 = dynamic_cast<D&>(br);
    D &dr3 = static_cast<D&>(*bp);
    D &dr4 = dynamic_cast<D&>(*bp);
    void *vp = bp;
    //bp = dynamic_cast<D*>(vp); //error: can not dynamic cast void*(no typeinfo)
    
    cout << "bp: " << typeid(bp).name() << endl;
    cout << "*bp: " << typeid(*bp).name() << endl;
    cout << "br: " << typeid(br).name() << endl;
    cout << "D: " << typeid(D).name() << endl;
    cout << "int: " << typeid(int).name() << endl; //typeid C++内置的typeinfo(编译时确定)
    return 0;
}
